package fina2.dcs.mail;

import fina2.dcs.mail.manager.MailPropsKey;
import fina2.dcs.mail.manager.MailUser;
import fina2.dcs.mail.owa.MailSenderImplOWA;

@SuppressWarnings("serial")
public class MailSender implements MailSenderBase {

	private MailSenderBase mailSenderImpl;

	public MailSender(MailUser mailUser) {
		switch (mailUser.getConnectionType()) {
		case MailPropsKey.MAIL_POP3_SMTP: {
			mailSenderImpl = new MailSenderSMTP(mailUser);
			break;
		}
		case MailPropsKey.MAIL_IMAP_SMTP: {
			mailSenderImpl = new MailSenderSMTP(mailUser);
			break;
		}
		case MailPropsKey.MAIL_OWA: {
			mailSenderImpl = new MailSenderImplOWA(mailUser);
			break;
		}
		case MailPropsKey.MAIL_EWS: {
			mailSenderImpl = new MailSenderSMTP(mailUser);
			break;
		}
		default: {
			throw new RuntimeException("Connection not Supported!");
		}
		}
	}

	@Override
	public void send(String messageText, String subject, String[] cc, String[] bcc, String... toMailUser) throws Exception {
		mailSenderImpl.send(messageText, subject, cc, bcc, toMailUser);
	}

	@Override
	public void connect() {
		mailSenderImpl.connect();
	}

	@Override
	public boolean isConected() {
		return mailSenderImpl.isConected();
	}

	@Override
	public void close() {
		mailSenderImpl.close();
	}

}
